define(['knockout','store', 'mConfirm', 'util','aPermissionCard','mUser'], function (ko,Store, MConfirm, Util,APermissionCard,MUser) {
    function ViewModel(params) {
        Util.extend(this, params);

        var scope = this;

        var store = new Store({
            model: MUser,
            id: 'userStore'
        });

        scope.card = {
            title: '用户列表',
            titleButtons: [],
            cardBodyTop:{
                name:'cmp:UserQueryForm',
                params:{
                    record:store.createModel()
                }
            },
            cardBody: {
                name: 'cmp:Grid',
                params: {
                    operations: [],
                    store: store,
                    displayFields: ['rowId', 'name','roleName','departmentName'],
                    onOperation: function (operation, record) {
                        switch (operation.name) {
                            case 'resetPassword':
                                var model = new MConfirm('是否重置密码？');

                                model.setProxy({url:'/rest/users/{0}/initPassword'.formatTpl(record.id())});
                                ko.root.openModal({
                                    title: '重置密码',
                                    level: 'warning',
                                    operation: operation.name,
                                    record: model,
                                    commit: function (btn,record, callback) {
                                        record.save(callback,true);
                                    }
                                });
                                break;
                        }
                    }
                }
            }
        };

        this.callParent(params);
    }

    ViewModel.extend(APermissionCard);

    return ViewModel;
});
